const KoaRouter = require('@koa/router')
const { auth } = require('../middleware/auth.middleware')
const { add, getAllCarts, updateCartsById, removeBatchCartsByIds, selectAll } = require('../controller/carts.controller')
const { cartsValidator } = require('../middleware/carts.middleware')

/**购物车 */
const cartsRouter = new KoaRouter({ prefix: '/carts' })
/**添加到购物车 */
cartsRouter.post('/', auth, cartsValidator({
  goods_id: 'number'
}), add)
/**获取购物车列表 */
cartsRouter.get('/', auth, getAllCarts)
/**更新购物车列表 */
cartsRouter.patch('/:id', auth, cartsValidator({
  number: { type: 'number', required: false },
  selected: { type: 'bool', required: false }
}), updateCartsById)
/**删除购物车列表 */
cartsRouter.delete('/', auth, cartsValidator({
  ids: 'array'
}), removeBatchCartsByIds)
/**全选与全不选 */
cartsRouter.post('/checkAll', auth, selectAll)

module.exports = cartsRouter